package com.micro.service.common.enums;



import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author lv
 * @Description: * 900-999
 * 授权中心服务的状态码
 * @create 10:00 2017/12/29
 * @last modify by [lv 10:00 2017/12/29 ]
 * @return
 */
public enum AuthorizationServerEnum {

    /**
     * @Description: 登陆成功
     * @author lv
     * @create 9:55 2017/12/29
     * @last modify by [lv 9:55 2017/12/29 ]
     * @return
     */
    LoginSuccess(Boolean.TRUE, "900", "登陆成功！"),

    /**
     * @Description: 登陆失败
     * @author lv
     * @create 9:55 2017/12/29
     * @last modify by [lv 9:55 2017/12/29 ]
     * @return
     */
    LoginFail(Boolean.FALSE, "901", "登陆失败！"),

    /**
     * @Description: 用户名或密码错误
     * @author lv
     * @create 14:22 2018/1/18
     * @last modify by [lv 14:22 2018/1/18 ]
     * @return
     */
    UserNameOrPasswordException(Boolean.FALSE, "902", "用户名或密码错误"),

    /**
     * @Description: 用户不存在
     * @author lv
     * @create 14:44 2018/1/18
     * @last modify by [lv 14:44 2018/1/18 ]
     * @return
     */
    UserNotExistedException(Boolean.FALSE, "903", "用户不存在"),

    /**
     * @Description:ACCESS_TOKEN失效
     * @author lv
     * @create 19:16 2018/1/26
     * @last modify by [lv 19:16 2018/1/26 ]
     * @return
     */
    NVALID_TOKEN(Boolean.FALSE, "904", "ACCESS_TOKEN失效"),

    /**
     * @Description: 密码错误
     * @author lv
     * @create 9:51 2018/2/8
     * @last modify by [lv 9:51 2018/2/8 ]
     * @return
     */
    UserPasswordException(Boolean.FALSE, "905", "密码错误"),

    /**
     * 验证码错误
     */
    ValidateCodeNull(Boolean.FALSE, "906", "验证码不能为空"),
    /**
     * 验证码错误
     */
    ValidateCodeException(Boolean.FALSE, "907", "验证码错误"),
    /**
     * 验证码发送失败
     */
    ValidateCodeSendException(Boolean.FALSE, "908", "验证码发送失败"),
    /**
     * 验证码已失效
     */
    ValidateCodeInvalid(Boolean.FALSE, "909", "验证码已失效"),
    /**
     * 登出成功
     */
    LogoutSuccess(Boolean.TRUE, "910", "登出成功"),

    /**
     * 用户未登录
     */
    UserUnloginException(Boolean.FALSE, "911", "用户未登录"),

    /**
     * 获取AccessToken失败
     */
    GetAccessTokenFail(Boolean.FALSE, "912", "获取AccessToken失败"),

    /**
     * clientId为空
     */
    ClientIdNull(Boolean.FALSE, "913", "clientId不能为空"),

    /**
     * 获取AccessToken失败
     */
    RequestIsNull(Boolean.FALSE, "914", "请求参数不能为空"),
    /**
     * 返回简单的成功结果
     */
    CreateOrderSucces(Boolean.TRUE, "999", "授权中心请求服务成功"),

    /**
     * @Description: 逻辑删除客户端
     * @author lv
     * @create 9:55 2017/12/29
     * @last modify by [lv 9:55 2017/12/29 ]
     * @return
     */
    LogicallyDeleteClient(Boolean.TRUE, "998", "逻辑删除客户端成功"),

    AccountCenterException(Boolean.TRUE,"920","用户中心错误"),

    InvalidTokenException(Boolean.TRUE,"401","token无效"),
    /**
     * 获取AccessToken失败
     */
    RefAccessTokenFail(Boolean.FALSE, "915", "刷新AccessToken失败"),

    UserIsDel(Boolean.FALSE,"916","用户已注销")

    ;

    private Boolean success;
    private String code;
    private String message;

    AuthorizationServerEnum(Boolean success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public static Map<String, String> getAll() {
        Map<String, String> retMap = new LinkedHashMap<String, String>();
        AuthorizationServerEnum[] enumArr = AuthorizationServerEnum.values();
        for (AuthorizationServerEnum aEnum : enumArr) {
            retMap.put(aEnum.getCode(), aEnum.getMessage());
        }
        return retMap;
    }

    public static AuthorizationServerEnum getByCode(String code) {
        AuthorizationServerEnum[] enumArr = AuthorizationServerEnum.values();
        for (AuthorizationServerEnum aEnum : enumArr) {
            if (aEnum.getCode().equals(code)) {
                return aEnum;
            }
        }
        return null;
    }

    public static AuthorizationServerEnum getByMessage(String message) {
        AuthorizationServerEnum[] enumArr = AuthorizationServerEnum.values();
        for (AuthorizationServerEnum aEnum : enumArr) {
            if (aEnum.getMessage().equals(message)) {
                return aEnum;
            }
        }
        return null;
    }


    public Boolean getSuccess() {
        return success;
    }


    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String errorMsg) {
        this.message = message;
    }
}
